var MONTHS = ["January", "February","March", "April","May","June","July","August","September","October","November","December"];

function parseJSON(data) {
    return window.JSON && window.JSON.parse ? window.JSON.parse( data ) : (new Function("return " + data))(); 
}

function confirmDialog(content, callbackFunction) {
	require([ "dijit/Dialog", "dijit/layout/BorderContainer",
			"dijit/layout/ContentPane", "dijit/form/Button","dojo/domReady!" ], 
	function(Dialog, BorderContainer,ContentPane, Button) {
		 dojo.declare("MyDialog", [ Dialog ], {
			title: "Confirm Dialog",
			id: "confirmDialog",
			  
	        postCreate: function(){
	          var self = this;
	          this.inherited(arguments);
	          var bc = new BorderContainer({style: "height: 100px; width: 350px;"});
	          var contentTop = new ContentPane({
	              region: "top",
	              content: content
	          });
	          bc.addChild(contentTop);
	          
	          var contentBottom = new ContentPane({
	              region: "bottom",
	              style :"top: 40px;text-align: right;"
	          });
	          this.okButton = new Button( { label: "OK" , class : "confirmDialogButtons"} );
	          this.cancelButton = new Button( { label: "Cancel", class : "confirmDialogButtons" } );
	          
	          contentBottom.set("content", [this.okButton.domNode,this.cancelButton.domNode]);
	          bc.addChild(contentBottom);
	         
	          this.okButton.on('click', function() {
	        	callbackFunction();
	            self.destroy();
	          });
	          this.cancelButton.on('click', function(){
	            self.destroy();
	          });
	          
	          this.addChild(bc);
	          bc.startup();
	        },
	      });
		var dialog = new MyDialog();
		dialog.show();
	});
}

function createWarningDialog(content) {
	require(["dijit/Dialog", "dojo/domReady!"], function(Dialog){
	    myDialog = new Dialog({
	        title: "Warning",
	        content: content,
	        style: "width: 300px"
	    });
	    myDialog.show();
	});
}

function createCDDialog(title, callback) {
	require(["dojo/store/Memory","dojo/data/ObjectStore","dojo/_base/xhr","dojo/domReady!"], function(Memory, ObjectStore, xhr){
        xhr.get({
            url: "retriveData?operation=getProducers",
            handleAs: "json"
        }).then(function(data){
       	 	producerStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
       	 	var producerCombo = dijit.byId("producerCombo");
       	 	producerCombo.set('store', producerStore);
       	 	
       	 	xhr.get({
       	 		url: "retriveData?operation=getTypes",
       	 		handleAs: "json"
       	 		}).then(function(data){
       	 			typeStore =  new ObjectStore({ objectStore:new Memory({ data: data.items }) });
       	 			var typeCombo = dijit.byId("typeCombo");
       	 			typeCombo.set('store', typeStore);
       	 			var dlg = dijit.byId("CDDialog");
       	 			dlg.set('title', title); 
       	 			dlg.show();
       	 			
       	 			callback();
       	 		});
        });
	});
}